package com.changgou.order.controller;


import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.order.feign.CartFeign;
import com.google.common.cache.AbstractCache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/wcart")
public class WebCartController {

    @Autowired
    private CartFeign cartFeign;

    @GetMapping("/list")
    public String list(Model model){
        //获取购物车列表数据,通过feign调用
        Map<String,Object> cartMap = cartFeign.list();
        System.out.println("cartMap : "+cartMap);
        model.addAttribute("items",cartMap);
        //跳转到cart.html页面
        return "cart";
    }

    @GetMapping("/add")
    @ResponseBody
    public Result add(String skuId,Integer num){
        //添加购物车的方法
        cartFeign.add(skuId,num);
        //再次加载页面
        Map map = cartFeign.list();
        System.out.println("cartMap : "+map);
        return new Result(true, StatusCode.OK,"添加购物车成功",map);
    }


}
